package com.zyylr.classroomreservationsystem.utils;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

/**
 * 活动列表收集，工具类，不可实例化
 */
public class ActivityCollector {
    private ActivityCollector() {
    }

    private static List<Activity> activityList = new ArrayList<>();

    public static void addActivity(Activity activity) {
        activityList.add(activity);
    }

    public static void removeActivity(Activity activity) {
        activityList.remove(activity);
    }

    /**
     * 销毁所有Activity
     */
    public static void finishAll() {
        for (Activity activity : activityList) {
            //如果活动不是正在销毁中，那么就把它销毁掉
            if (!activity.isFinishing()) {
                activity.finish();
            }
        }
    }
}
